package top.suven.base.http.admin.config.dao;

import org.apache.ibatis.annotations.*;
import top.suven.base.core.mybatis.crud.CommonCrudMapper;
import top.suven.base.http.admin.config.model.MqFailInfo;

import java.util.List;

/**
 * @Title: MqFailInfoWebDao.java
 * @Description: MQ消费失败信息的数据交互类
 * @author lixiangling
 * @date   2018/09/06 18:49:45
 * @version V1.0.0
 * ----------------------------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 * ----------------------------------------------------------------------------
 *
 */
public interface MqFailInfoWebDao extends CommonCrudMapper<MqFailInfo> {
    @Select("<script> " +
    "select * from  cmm_mq_fail_info where  mq_fail_id in " +
    "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
    "#{item} " +
    "</foreach> " +
    "</script>")
    @Results(
        id="mqFailInfo",
        value = {
            @Result(column = "mq_fail_id" , property = "mqFailId"),
			@Result(column = "topic_name" , property = "topicName"),
			@Result(column = "mq_message" , property = "mqMessage"),
			@Result(column = "exec_status" , property = "execStatus"),
			@Result(column = "reason" , property = "reason"),
			@Result(column = "create_time" , property = "createTime"),
			@Result(column = "modify_time" , property = "modifyTime"),
			@Result(column = "deal_info" , property = "dealInfo"),
			@Result(column = "fail_info" , property = "failInfo"),
			@Result(column = "global_id" , property = "globalId")
        }
    )
    List<MqFailInfo> getSysRoleMenuByRoleCodeList(@Param("idList") List<Long> idList);
    /**
     * @Title: 删除MQ消费失败信息信息
     * @Description:id @{Link Long[]}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/09/06 18:49:45
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @Update("<script> " +
            "UPDATE cmm_mq_fail_info set exec_status='0'"+
            "WHERE mq_fail_id IN " +
            "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach> " +
            "</script>")
    void del(@Param("idList") List<Long> idList);
    /**
     * @Title: 取消MQ消费失败信息信息
     * @Description:id @{Link Long}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/09/06 18:49:45
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @Update("<script> " +
            "UPDATE cmm_mq_fail_info  " +
            "SET exec_status = 1,reason=#{reason}  " +
            "WHERE mq_fail_id IN " +
            "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach> " +
            "</script>")
    void cancel(@Param("reason") String reason, @Param("idList") List<Long> idList);
    /**
     * @Title: 获取待处理的MQ消费失败信息信息
     * @Description: ids @{Link List}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/09/06 18:49:45
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @Update("<script> " +
            "select * from cmm_mq_fail_info  " +
            "WHERE exec_status = 0 and mq_fail_id IN " +
            "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach> " +
            "</script>")
    @ResultMap("mqFailInfo")
    List<MqFailInfo> getMqFailInfoListByInit(@Param("idList") List<Long> idList);
    /**
     * @Title: 获取待处理的MQ消费失败信息信息
     * @Description: topicName @{Link String}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/09/06 18:49:45
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @Update("<script> " +
            "select * from cmm_mq_fail_info  " +
            "WHERE exec_status = 0 and topic_name=#{topicName} "+
            "</script>")
    @ResultMap("mqFailInfo")
    List<MqFailInfo> getMqFailInfoListByTopicNameAndInit(@Param("topicName") String topicName);
}